﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;
namespace ConfExpert.Forms.Sistem
{
    public partial class Yetki : XForm
    {
        public Yetki()
        {
            InitializeComponent();
        }

        //DataSet d;
        //DataTable dtU, dtD;
        private void Yetki_Load(object sender, EventArgs e)
        {

            gridView1.Init("GetYetkiler");
            gridView1.AddDetailGrid(gridView2, "YetkiId", 1);
            gridView1.AddDetailGrid(gridView3, "YetkiId", 2);

            gridView1.SetViewCaption("Yetkiler");
            gridView2.SetViewCaption("Kullanıcılar");
            gridView3.SetViewCaption("Departmanlar");
            //d = ExecuteDataSet("GetUsrDept");
            //dtU = d.Tables[0];
            //dtU.PrimaryKey = new DataColumn[] { dtU.Columns["UserId"] };
            //dtD = d.Tables[1];
            //RepositoryItemGridLookUpEdit riU = GetCustomGLE(dtU, "Username", "UserId");
            //RepositoryItemGridLookUpEdit riD = GetCustomGLE(dtD, "Name", "DepartmentId");

            //gridView2.Columns["UserId"].ColumnEdit = riU;
            //gridView3.Columns["DepartmentId"].ColumnEdit = riD;
            gridView1.FormatAsDateTime("Tarih");
            gridView1.MakeRowSelectable();
            gridView1.MakeReadOnly();
            gridView1.MakeColumnInvisible("Aciklama");
            gridView2.MakeColumnInvisible("YetkiId");
            gridView3.MakeColumnInvisible("YetkiId");
            splitContainerControl2.AutoSize();
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            btnYeni.ItemClick += btnYeni_ItemClick;

            gridView1.AddAutoIncrementalPK("YetkiId");

            gridView2.OptionsView.NewItemRowPosition =
            gridView3.OptionsView.NewItemRowPosition =
            DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gridView2.Columns["UserId"].OptionsColumn.AllowEdit = true;
            //gridView2.MakeEditable("UserId");

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
            gridView3.BestFitColumns();

            gridView1.MoveLast();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            gridView2.EndEditing();
            gridView3.EndEditing();

            gridView1.Update("", "Yetki");
            gridView2.Update("", "YetkiUser");
            gridView3.Update("", "YetkiDepartment");
        }

        void btnYeni_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnKaydet.PerformClick();
            gridView1.RefreshDataSource("InsYetki");
            gridView1.MoveLast();
        }

    }
}
